package main
import(
	"fmt"
	"encoding/json"
)

func main(){
	monster := Monster{"npc1",500,"ack"}
	// 将monster 变量序列化为 json格式字符串
	jsonStr,err :=json.Marshal(monster)
	if err!=nil{
		fmt.Println("json 处理错误",err)
	}
	fmt.Println("jsonStr",string(jsonStr)) // jsonStr {"name":"npc1","age":500,"Skill":"ack"}

	monster2 := Monster2{"npc3",400,"def"}
	jsonStr,err =json.Marshal(monster2)
	fmt.Println("Monster2=",string(jsonStr)) // Monster2= {"Name":"npc3","Age":400,"Skill":"def"}
}

type Monster struct {
	Name string `json:"name"` // `json:"name"`就是struct tag
	Age int `json:"age"`
	Skill string `json:"skill"` 
}

type Monster2 struct {
	Name string 
	Age int 
	Skill string 
}
